package com.xmall.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xmall.auth.dao.SysRoleMenuRelationMapper;
import com.xmall.auth.entity.SysRoleMenuRelation;
import com.xmall.auth.service.ISysRoleMenuRelationService;
import com.xmall.common.config.PlatformContant;
import com.xmall.common.config.PojoUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 后台角色菜单关系表 服务实现类
 * </p>
 *
 * @author liuzh
 * @since 2020-06-14
 */
@Service
public class SysRoleMenuRelationServiceImpl extends ServiceImpl<SysRoleMenuRelationMapper, SysRoleMenuRelation> implements ISysRoleMenuRelationService {
        @Autowired
        SysRoleMenuRelationMapper sysRoleMenuRelationMapper;
        @Override
        public boolean saveSysRoleMenuRelation(SysRoleMenuRelation sysRoleMenuRelation) {
        PojoUtils.setSysProperties(sysRoleMenuRelation, PlatformContant.OpType.insert);
        return save(sysRoleMenuRelation);
        }

        @Override
        public boolean updateSysRoleMenuRelation(Long id , SysRoleMenuRelation sysRoleMenuRelation) {
        SysRoleMenuRelation oldSysRoleMenuRelation = getById(id);
        BeanUtils.copyProperties(sysRoleMenuRelation, oldSysRoleMenuRelation);
        PojoUtils.setSysProperties(oldSysRoleMenuRelation, PlatformContant.OpType.update);
        boolean update = update(
        oldSysRoleMenuRelation,
        new QueryWrapper<SysRoleMenuRelation>()
        .lambda().eq(SysRoleMenuRelation::getId, id)
        );
        return update;
        }

        @Override
        public boolean deleteSysRoleMenuRelation(Long id) {
        boolean b = removeById(id);
        return b;
        }

        @Override
        public SysRoleMenuRelation getSysRoleMenuRelation(Long id) {
        SysRoleMenuRelation sysRoleMenuRelation = getById(id);
        return sysRoleMenuRelation;
        }
}
